let testData = require('../Data/testData')

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },

    // use this for initialization
    onLoad: function () {
        this.playerNode = cc.find('Canvas/Player')


        this.vecBP = cc.v2(Math.sin(((this.playerNode.rotation) / 180) * Math.PI), Math.cos(((this.playerNode.rotation) / 180) * Math.PI)) // 创建子弹节点与player的向量
        this.rotateDir = cc.pToAngle(this.vecBP) // 获取向量的弧度
        this.node.rotation = -cc.radiansToDegrees(this.rotateDir) - 90 // 将弧度转化为角度
        // this.node.rotation =this.playerNode.rotation;
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {

        this.bulletMove()

    },

    /**
     *
     * @description 根据初始化时候的向量方向进行运动
     */
    bulletMove: function () {
        this.node.x += this.vecBP.x * testData.bulletSpeed * window.speedCoefficient / cc.pLength(this.vecBP)
        this.node.y += this.vecBP.y * testData.bulletSpeed * window.speedCoefficient / cc.pLength(this.vecBP)
    }
});
